// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.sql.SQLException;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.core.znet.SteamUtils;
import zombie.network.GameServer;
import zombie.network.ServerWorldDatabase;

@CommandName(
    name = "banid"
)
@CommandArgs(
    required = {"(.+)"}
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_BanSteamId"
)
@RequiredRight(
    requiredRights = 48
)
public class BanSteamIDCommand extends CommandBase {
    public BanSteamIDCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() throws SQLException {
        String string = this.getCommandArg(Integer.valueOf(0));
        if (!SteamUtils.isSteamModeEnabled()) {
            return "Server is not in Steam mode";
        } else if (!SteamUtils.isValidSteamID(string)) {
            return "Expected SteamID but got \"" + string + "\"";
        } else {
            LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " banned SteamID " + string, "IMPORTANT");
            ServerWorldDatabase.instance.banSteamID(string, "", true);
            long _long = SteamUtils.convertStringToSteamID(string);

            for (int _int = 0; _int < GameServer.udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(_int);
                if (udpConnection.steamID == _long) {
                    GameServer.kick(udpConnection, "UI_Policy_Ban", null);
                    udpConnection.forceDisconnect("command-ban-sid");
                    break;
                }
            }

            return "SteamID " + string + " is now banned";
        }
    }
}
